<?php
/**
 * DotHerbert
 *
 * @package    Core
 * @subpackage Stub
 * @copyright  2009 extreme-programmers
 * @license    http://dotherbert.extreme-programmers.com/license   BSD License
 * @version    $Id: FilesystemStub.php 108 2009-05-13 19:09:31Z johannes.trink@extreme-programmers.com $
 */

namespace dotherbert\core\stub;

/**
 * Stub for filesystem functions
 *
 * @package    Core
 * @subpackage Stub
 * @author     Johannes Trink <johannes.trink@extreme-programmers.com>
 */
class FilesystemStub
{
    /**
     * Instance
     *
     * @var DotHerbert_Core_Stub_FilesystemStub
     */
    private static $instance;

    /**
     * Constructor
     *
     * @return void
     */
    private function __construct()
    {
    }

    /**
     * Clone
     *
     * @return void
     */
    private function __clone()
    {
    }

    /**
     * Get instance
     *
     * @return DotHerbert_Core_Stub_FilesystemStub
     */
    public static function getInstance()
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * Set instance
     *
     * @param  DotHerbert_Core_Stub_FilesystemStub
     * @return void
     */
    public static function setInstance(self $instance)
    {
        self::$instance = $instance;
    }

    /**
     * Unset instance
     *
     * @return void
     */
    public static function unsetInstance()
    {
        self::$instance = null;
    }

    /**
     * File exists
     *
     * @param string $filename
     * @link  http://de.php.net/manual/en/function.file-exists.php
     */
    public function fileExists($file)
    {
        return file_exists($file);
    }

    /**
     * File get contents
     *
     * @param  string   $filename
     * @param  int      $flags
     * @param  resource $context
     * @param  int      $offset
     * @param  int      $maxlen
     * @return bool
     */
    public function fileGetContents($filename, $flags = 0, $context = null, $offset = null,
                                    $maxlen = null)
    {
        if (null == $maxlen) {
            return file_get_contents($filename, $flags, $context, $offset);
        } else {
            return file_get_contents($filename, $flags, $context, $offset, $maxlen);
        }
    }

    /**
     * File put contents
     *
     * @param  string   $filename
     * @param  mixed    $data
     * @param  int      $flags
     * @param  resource $context
     * @return int
     */
    public function filePutContents($filename, $data, $flags = 0, $context = null)
    {
        return file_put_contents($filename, $data, $flags, $context);
    }
}